package acm.浙江24赛;

import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class 涂色 {
    public static void main(String[] args) {
        Reader sc = new Reader();
        n = sc.nextInt();
        chars = new char[n + 1][];
        char[] prototype = new char[n + 1];
        Arrays.fill(prototype, 1, n + 1, 'a');
        for (int i = 1; i < chars.length; i++) {
            chars[i] = prototype.clone();
        }
        int m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            int type = sc.nextInt();
            switch (type) {
                case 1:
                    h1(sc.nextInt(), sc.next());
                    break;
                case 2:
                    h2(sc.nextInt(), sc.next());
                    break;
                case 3:
                    h3(sc.nextInt(), sc.next());
                    break;
                case 4:
                    h4(sc.nextInt(), sc.next());
                    break;
                case 5:
                    h5(sc.nextInt());
                    break;
            }
        }
    }

    static char[][] chars;
    static int n;

    public static void h1(int row, String s) {
        Arrays.fill(chars[row], 1, n + 1, s.charAt(0));
    }

    public static void h2(int col, String s) {
        char c = s.charAt(0);
        for (int i = 1; i <= n; i++) {
            chars[i][col] = c;
        }
    }

    public static void h3(int s, String str) {
        char c = str.charAt(0);
        if (s>n){
        }
        for (int i = 1; i < s && i <= n; i++) {
            if (s - i > n) {
                continue;
            }
            chars[i][s - i] = c;
        }
    }

    public static void h4(int s, String str) {
        char c = str.charAt(0);
        if (s >= 0) {
            for (int i = s + 1; i <= n; i++) {    //s>-1就不可能越界
                chars[i][i - s] = c;    //s+1<=n,i>=s+1 i-s>=1
            }
        } else {
            try {
                for (int i = 1; i - s <= n; i++) {
                    chars[i][i - s] = c;
                }
            } catch (Exception e) {
                System.exit(0);
            }
        }
    }

    public static void h5(int row) {
        for (int i = 1; i < chars[row].length; i++) {
            System.out.print(chars[row][i]);
        }
        System.out.println();
    }

    static class Reader {
        private PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer tokenizer = new StringTokenizer("");

        private String innerNextLine() {
            try {
                return reader.readLine();
            } catch (IOException ex) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!tokenizer.hasMoreTokens()) {    //内存中没有
                String nextLine = innerNextLine();
                if (nextLine == null) {     //且没有下一行
                    return false;
                }
                tokenizer = new StringTokenizer(nextLine);  //读入一行
            }
            return true;
        }

        public String nextLine() {
            tokenizer = new StringTokenizer("");    //清空内存中的字符
            return innerNextLine();
        }

        public void clear() {
            tokenizer = new StringTokenizer("");
        }

        public String next() {
            hasNext();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
//    public BigInteger nextBigInt() {
//        return new BigInteger(next());
//    }
    }

}
